package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.mapper.EduTeacherMapper;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李红磊
 * @since 2021-06-02
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {





    @Override
    public Map<String, Object> getTeacherFrontList(Page<EduTeacher> pageTeacher) {

        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");

        this.page(pageTeacher, wrapper);//分页的数据封装到pageTeacher中

        //将pageTeacher中的数据封装到map，然后返回
        List<EduTeacher> records = pageTeacher.getRecords();//这一页的数据集合
        long current = pageTeacher.getCurrent();//当前页数
        long pages = pageTeacher.getPages();//总页数
        long size = pageTeacher.getSize();//每页展示的数据量
        long total = pageTeacher.getTotal();//总纪录数

        boolean hasNext = pageTeacher.hasNext();//当前是否还有下一页（比如如果到了最后一页，就没有下一页）
        boolean hasPrevious = pageTeacher.hasPrevious();//当前是否还有上一页

        Map<String, Object> map = new HashMap<>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }
}
